//get the sum of a and b which are row vectors in GF(p) field. 
//p must be a prime number.
//a b must be row vectors of equal size
//elements of a and b must be integers in the range [0, p-1].
function c = gfadd(a, b, p)
  [lhs rhs] = argn();
  if rhs < 3
    p = 2;
  end
  if p < 2 | p ~= int(p)
    error('p must be an prime number');
  end
  if max(a) > p-1 | max(b) > p-1 | min(a) < 0 | min(b) < 0
    error('elements of a and b must integers in the range [0, p-1]')
  end
  if a ~= int(a)
    error('elements of a and b must integers in the range [0, p-1]')
  end
  if b ~= int(b)
    error('elements of a and b must integers in the range [0, p-1]')
  end
  if size(a, 1) ~= 1 | size(b,1) ~= 1
    error('a and b must be row vectors');
  end

  len1 = size(a, 2);
  len2 = size(b, 2);
  if len1 < len2
    // append zeros to end of a
    len = len2;
    a = [a zeros(1, len2-len1)];
  else
    // append zeros to end of b
    len = len1
    b = [b zeros(1, len1 - len2)];
  end
  
  c = modulo(a+b, p)
endfunction

